<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">jQuery.escapeSelector()</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/css/">CSS</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/jQuery.escapeSelector/" target="_blank">jQuery.escapeSelector()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<article class="entry method" id="jQuery-escapeSelector1"><h2 class="section-title">
<span class="name">jQuery.escapeSelector( selector )</span><span class="returns">Returns: <a href="http://api.jquery.com/Types/#Selector">Selector</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>Description: </strong>Escapes any character that has a special meaning in a CSS selector.</p>
<ul class="signatures"><li class="signature">
<h4 class="name">
<span class="version-details">version added: <a href="/category/version/3.0/">3.0</a></span><a href="#jQuery-escapeSelector-selector" id="jQuery-escapeSelector-selector"><span class="icon-link"></span>jQuery.escapeSelector( selector )</a>
</h4>
<ul><li>
<div><strong>selector</strong></div>
<div>Type: <a href="http://api.jquery.com/Types/#Selector">Selector</a>
</div>
<div>A string containing a selector expression to escape.</div>
</li></ul>
</li></ul>
<div class="longdesc" id="entry-longdesc">
<p>This method is useful for situations where a class name or an ID contains characters that have a special meaning in CSS, such as the dot or the semicolon.</p>
<p>The method is essentially a shim for the <a href="https://drafts.csswg.org/cssom/#the-css.escape()-method">CSS Working Group's CSS.escape() method</a>. The main difference is that <code>$.escapeSelector()</code> can be reliably used in all of jQuery's supported browsers.</p>
</div>
<section class="entry-examples" id="entry-examples"><header><h2>Examples:</h2></header><div class="entry-example" id="example-0">
<p>Escape an ID containing a hash.</p>
<div class="syntaxhighlighter javascript">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$.escapeSelector( <span class="string">"#target"</span> ); <span class="comment">// "\#target"</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-1">
<p>Select all the elements having a class name of <code>.box</code> inside a <code>div</code>.</p>
<div class="syntaxhighlighter javascript">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$( <span class="string">"div"</span> ).find( <span class="string">"."</span> + $.escapeSelector( <span class="string">".box"</span> ) );</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div></section>
</div></article>
</article>